#ifndef __PVMDATASOURCEWAV_H__
#define __PVMDATASOURCEWAV_H__

#include "pvm/pvmapi.h"
#include "lib/pvmsystem.h"

#include "lib/decoders/wav/pvmwavstruct.h"

#include "lib/memory/pvmmemory.h"

class IPvmInStream;

class PVMDataSourceWAV : public PVMAllocableObject
{
protected:
	PVMCriticalSection critical;
	pvm_bool			criticalInitialized;
	pvm_int				refCount;

public:
	IPvmInStream*	stream;
	pvm_int8* initial;
	pvm_int initialSize;
	pvm_int posInInitial;
	pvm_int dataOffset;
	pvm_int dataSize;
	FmtHeader formatHeader;
	pvm_int sampleSizeInBytes;
	pvm_int64 offsetInSamples;

protected:
	pvm_bool Init(IPvmInStream* srcStream, pvm_bool copyStream, pvm_int8* initial, pvm_int initialSize, pvm_int dataOffset, pvm_int dataSize, FmtHeader& header);
	PVMDataSourceWAV();
public:
	virtual ~PVMDataSourceWAV();

	static PVMDataSourceWAV* Create(IPvmInStream* srcStream, pvm_bool copyStream, pvm_int8* initial, pvm_int initialSize, pvm_int dataOffset, pvm_int dataSize, FmtHeader& header);
	PVMDataSourceWAV* CreateCopy();
	pvm_int FillBuffer(void *buffer, pvm_int sizeInSamples);

	pvm_bool SetPositionMS(pvm_int32 position);
	pvm_int32 GetPositionMS();

	pvm_bool IsDataEnd();
	pvm_bool SeekAtStart();
	pvm_bool SeekAtSamplePos(pvm_int64 pos);

	IPvmInStream& Stream();

	pvm_int GetRefCount();
	pvm_int Release();
	pvm_int AddRef();
};

#endif
